//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Physics2D/Objects/Trigger.h"

namespace Engine
{
namespace Physics2D
{

	//
	// Physics World
	//

	class PhysicsWorld
	{
	// types
	private:
		typedef AutoPtr< b2World >		world_ptr_t;


	// variables
	private:
		world_ptr_t			_world;
		TriggerListener		_triggerListener;


	// methods
	public:
		PhysicsWorld ()
		{
		}


		~PhysicsWorld ()
		{}


		void Create ()
		{
			Destroy();

			_world = new b2World( b2Vec2() );
			_world->SetContactListener( &_triggerListener );
		}


		void Destroy ()
		{
			_world = null;
		}


		void Update (float timeDelta, uint velSteps = 6, uint posSteps = 2)
		{
			_world->Step( timeDelta, velSteps, posSteps );
		}


		void SetGravity (const vec2 &value)		{ _world->SetGravity( Utils::Vec2( value ) ); }

		vec2 GetGravity ()	const				{ return Utils::Vec2( _world->GetGravity() ); }

		b2World *	GetWorld ()					{ return _world.ptr(); }
	};


}	// Physics2D
}	// Engine